﻿using FrameWork.Output;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ServerUI
{
    public partial class OutputWnd : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public OutputWnd()
        {
            InitializeComponent();
        }

        private void OutputWnd_Shown(object sender, EventArgs e)
        {
            OutputPool.NewOutputGet += OutputPool_NewOutputGet;
        }

        void OutputPool_NewOutputGet(object sender, OutputEventArgs e)
        {
            if(this.ListVOutput.InvokeRequired)
            {
                OutputCollectorBase.NewOutputGetEventHandler del=new OutputCollectorBase.NewOutputGetEventHandler(OutputPool_NewOutputGet);
                this.ListVOutput.BeginInvoke(del, sender, e);
            }
            else
            {
                OutputItem i = e.Item;
                string ot="";
                Color fc=new Color();
                switch(i.OutputType)
                {
                    case OutputType.Info:
                        ot="Info";
                        fc = Color.BlueViolet;
                        break;
                    case OutputType.Waring:
                        ot="Waring";
                        fc = Color.YellowGreen;
                        break;
                    case OutputType.Error:
                        ot="Error";
                        fc = Color.OrangeRed;
                        break;
                }
                ListViewItem item = new ListViewItem(ot);
                item.ForeColor = fc;
                item.Tag = i;
                item.SubItems.Add(((OutputCollectorBase)sender).GetCollectorType());
                item.SubItems.Add(i.OutputString);
                ListVOutput.Items.Add(item);
                if(ListVOutput.TopItem!=null)
                    ListVOutput.TopItem = item;
            }
        }

        private void ListVOutput_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(ListVOutput.SelectedItems!=null)
            {
                if(ListVOutput.SelectedItems.Count>0)
                {
                    Program.ProperWnd.SetObject(ListVOutput.SelectedItems[0].Tag);
                }
            }
        }

    }
}
